<!DOCTYPE html>
<html>

<head>
    <include file="Share:meta" />
    <link rel="stylesheet" type="text/css" href="../Public/zTree_v3/css/zTreeStyle/zTreeStyle.css">

    <script src="../Public/plugins/jsFormat/jsFormat.js"></script>
    <script type="text/javascript" src="../Public/zTree_v3/js/jquery.ztree.core-3.5.js"></script>
   <script type="text/javascript" src="../Public/zTree_v3/js/jquery.ztree.excheck-3.5.js"></script>
    <script type="text/javascript">
        $(function(){
            var set = {
                data: {
                //  key: {
                //      title:"t"
                //  },
                    simpleData: {
                        enable: true
                    }
                },
                check: {
                    enable: true,
                    chkStyle: "checkbox",
                    checkboxType: {"Y":"p","N":"s"}
                },
                callback: {
                    beforeClick: beforeClick,
                    onClick: onClick
                }
            };
            
            var log, className = "dark";
            function beforeClick(treeId, treeNode, clickFlag) {
            };
            function onClick(event, treeId, treeNode, clickFlag) {
             // alert(treeNode.id + "---" + treeNode.name);
                // $("#cateId").val(treeNode.id);
                // $("#cateName").val(treeNode.name);
               
            };  
            var tree = {$tree};
            $("#treeDemo").html();
            $.fn.zTree.init($("#treeDemo"), set, tree);

            //选中节点
            AssignCheck({$authlist});
        });
     //获取所有选中节点的值
        function GetCheckedAll() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            var nodes = treeObj.getCheckedNodes(true);
            var menuIds ="";
            for (var i = 0; i < nodes.length; i++) {
                menuIds += nodes[i].id+",";
            }
            return menuIds;
        }    
        
        //全选
        function CheckAllNodes() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            treeObj.checkAllNodes(true);
        }

        //全取消
        function CancelAllNodes() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            treeObj.checkAllNodes(false);
        }
        
        //选中指定的节点
        function AssignCheck(jsonArr) {
            if (jsonArr){
                var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
                $.each(jsonArr, function(idx, item){
                    treeObj.checkNode(treeObj.getNodeByParam("id", item['menuid'], null), true, false);
                });
            }
   //         treeObj.checkNode(treeObj.getNodeByParam("id", "3", null), true, true);

        }
        //禁用、解禁选中节点
        function Disabled1() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            var nodes = treeObj.getCheckedNodes();

            for (var i = 0; i < nodes.length; i++) {
                treeObj.setChkDisabled(nodes[i], true);
            }
        }
        function Disabled2() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            var nodes = treeObj.getCheckedNodes();

            for (var i = 0; i < nodes.length; i++) {
                treeObj.setChkDisabled(nodes[i], false);
            }
        }
        function submitForm(){
            var menuIds =  GetCheckedAll();
            $("#menuIds").val(menuIds);
            $("#form1")[0].submit();
        };
    </script>
</head>

<body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">
        <include file="Share:header" />
        <include file="Share:left" />
        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>角色<small></small></h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                    <li class="active">新增、修改</li>
                </ol>
            </section>
            <!-- Main content -->
            <section class="content">
                <div class="box box-info">
                    <div class="box-header with-border">
                        <h3 class="box-title"><empty name="Think.get.roleid">新增角色<else />角色详细信息</empty></h3>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form class="form-horizontal" id="form1" action="__APP__/Admin/Role/detail" method="post">
                        <input type="hidden" name="roleid" value="{$info.roleid}"></input>
                        <input type="hidden" id="menuIds" name="menuIds" ></input>
                        <div class="box-body">
                            <div class="form-group">
                                <label for="inputEmail3" class="col-sm-2 control-label">角色名称</label>
                                <div class="col-sm-10">
                                    <input type="text" name="rolename" id="inputEventCode" class="form-control" value="{$info.rolename}" placeholder="" required="required"  autocomplete="off">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputEmail3" class="col-sm-2 control-label">角色描述</label>
                                <div class="col-sm-10">
                                    <input type="text" name="remark" id="inputEventCode" class="form-control" value="{$info.remark}"  autocomplete="off">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputEmail3" class="col-sm-2 control-label">菜单</label>
                                <div class="col-sm-10">
                                    <div class="controls" style="width: 270px; height: auto; border: solid 1px #DDDDDD; display: block;scroll:auto;">
                                    <ul id="treeDemo" class="ztree"></ul>
                                </div>
                                </div>
                            </div>

                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer col-sm-offset-2">
                            <button type="button" onClick="javascript:submitForm();" class="btn btn-primary">
                                <eq name="info" value="">新增
                                    <else />保存</eq>
                            </button>
                            <a class="btn btn-warning" href="__APP__/Admin/Role/rlist" role="button">返回</a>
                        </div>
                        <br>
                        <!-- /.box-footer -->
                    </form>
                </div>
              
            </section>
            <!-- /.content -->
        </div>
        <!-- /.content-wrapper -->
        <include file="Share:copyright" />
        <include file="Share:setting" />
    </div>
    <include file="Share:js" />
    <script type="text/javascript">
    $("#AdminManager").addClass("active");
    $("#role_list").addClass("active");
   

    </script>
</body>

</html>
